import { listAllCity, listAllWarehouse } from '@/services/forecastDimension';

export default {
  namespace: 'forecastDimension',
  state: {
    cityList: [],
    warehouseList: [],
  },
  effects: {
    *listCity({ payload }, { put, call }) {
      const resp = yield call(listAllCity, payload);
      const { state, data } = resp;
      if (state === 0) {
        yield put({
          type: 'save',
          payload: { cityList: data },
        });
      }
    },

    *listWarehouse({ payload }, { put, call }) {
      const resp = yield call(listAllWarehouse, payload);
      const { state, data } = resp;
      if (state === 0) {
        yield put({
          type: 'save',
          payload: { warehouseList: data },
        });
      }
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
